import request from './request'

export interface LoginRequest {
  account: string
  password: string
}

export interface RegisterRequest {
  account: string
  name: string
  email: string
  password: string
  phone: string
}

export interface UserInfo {
  id: number
  account: string
  name: string
  email: string
  phone: string
  sex: number
  deptCode: string
  deptName: string
  createdAt: string
  updatedAt: string
}

export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

// 登录
export const login = (data: LoginRequest): Promise<ApiResponse<{ token: string; user: UserInfo }>> => {
  return request.post('/auth/login', data)
}

// 注册
export const register = (data: RegisterRequest): Promise<ApiResponse> => {
  return request.post('/auth/register', data)
}

// 获取用户信息
export const getUserInfo = (): Promise<ApiResponse<UserInfo>> => {
  return request.post('/auth/userInfo')
}

// 更新用户信息
export const updateUserInfo = (data: Partial<UserInfo>): Promise<ApiResponse> => {
  return request.post('/auth/updateInfo', data)
}

// 重置密码
export const resetPassword = (data: { oldPassword: string; newPassword: string; confirmPassword: string }): Promise<ApiResponse> => {
  return request.post('/auth/resetPassword', data)
}


